<template>
  <div class="wrapper-fixed">
    <div class="action-bar-wrapper">
      <el-col :span="24" class="action-bar">
        <el-input v-model="searchText" clearable placeholder="请输入专家姓名" style="width:300px"></el-input>
        <el-select v-model="searchOption" clearable placeholder="预约状态" style="margin:0 20px;">
          <el-option
            v-for="item in searchOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button type="primary" size="medium" @click="search">检索</el-button>
      </el-col>
    </div>

    <!-- 列表 -->
    <el-table
      :data="tableData"
      v-loading="tableLoadingShow"
      element-loading-text="拼命加载中"
      style="width: 100%">
      <el-table-column
        prop="user_name"
        label="联系人"
        width="100">
      </el-table-column>
      <el-table-column
        prop="contact_phone"
        label="联系方式"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="desc"
        label="情况说明"
        show-overflow-tooltip
        width="200">
      </el-table-column>
      <el-table-column
        prop="expert_name"
        label="专家"
        width="200">
        <template slot-scope="scope">
          <div @click.stop="showExpertDetail(scope.row.expert_id)" style="cursor:pointer;color:#409EFF">
            {{scope.row.expert_name}}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="预约状态"
        width="200">
        <template slot-scope="scope">
          <div>
            <el-tag v-show="scope.row.status==0">待处理</el-tag>
            <el-tag type="success" v-show="scope.row.status==1">已处理</el-tag>
<!--            <el-tag type="info" v-show="scope.row.status==2">拒绝</el-tag>-->
          </div>

        </template>
      </el-table-column>
      <el-table-column
        prop="created_at"
        show-overflow-tooltip
        label="提交申请时间"
        width="200"
      >
      </el-table-column>

      <el-table-column label="操作" width='300'>
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="confirmAppoint(scope.row.id,1)" v-if="scope.row.status==0">处理预约</el-button>
<!--          <el-button type="danger" size="mini" @click="confirmAppoint(scope.row.id,2)" v-if="scope.row.status==0">拒绝</el-button>-->
        </template>
      </el-table-column>
      <template slot="empty">
        <p v-if="admin_info.role==1">暂无数据</p>
        <p v-else>无权限查看，请联系管理员处理</p>
      </template>
    </el-table>
    <el-col :span="24" class="footer-bar">
      <div class="page-code">
        <el-pagination
          background
          :page-size="16"
          layout="prev, pager, next"
          :total="totalPage"
          :current-page="page"
          @current-change="pageChange"
        >
        </el-pagination>
      </div>
    </el-col>
    <!-- 列表end -->

    <!-- 个人信息 -->
    <el-dialog title="专家详情" :visible.sync="expertDetailVisible" @close="initData">
      <el-form :label-position="'left'" label-width="150px">
        <el-form-item label="logo">
          <div><img :src="expertDetail.photo_url" alt=""
                    style="width:60px;border-radius:50%;height:60px;object-fit:cover"></div>
        </el-form-item>
        <el-form-item label="姓名">
          <div>{{expertDetail.realname}}</div>
        </el-form-item>
        <el-form-item label="手机">
          <div>{{expertDetail.phone}}</div>
        </el-form-item>
        <el-form-item label="所在单位">
          <div>{{expertDetail.unit_name}}</div>
        </el-form-item>

        <el-form-item label="职称">
          <div>{{expertDetail.position}}</div>
        </el-form-item>
        <el-form-item label="擅长领域">
          <div>{{expertDetail.strengths}}</div>
        </el-form-item>
        <el-form-item label="专家标签">
          <div class="tag-wrapper">
            <span v-for="(item,index) of expertDetail.expert_label" :key="index">{{item}}</span>
          </div>
        </el-form-item>
        <el-form-item label="城市">
          <div>{{expertDetail.province}}{{expertDetail.city}}{{expertDetail.area}}{{expertDetail.address}}</div>
        </el-form-item>


        <el-form-item label="资质证明">
          <div>
            <img style="width:150px;height:150px;objectFit:cover;margin:10px" :src="item.img_url" alt=""
                 v-for="(item,index) of expertDetail.expert_qualification_img" :key="index">
          </div>
        </el-form-item>
        <el-form-item label="提交申请时间">
          <div>{{expertDetail.created_at}}</div>
        </el-form-item>
        <el-form-item label="审核时间">
          <div>{{expertDetail.auth_time}}</div>
        </el-form-item>
        <el-form-item label="审核状态">
          <div>
            <el-tag type="success" v-show="expertDetail.is_auth==1">正常</el-tag>
            <el-tag type="info" v-show="expertDetail.is_auth==3">注销</el-tag>
          </div>
        </el-form-item>


      </el-form>
    </el-dialog>
    <!-- 个人信息end -->
  </div>
</template>

<script>
  export default {
    name: "order_list",
    data(){
      return{
        searchText:'',
        searchOption: '',
        searchOptions: [
          {label: '待处理', value: 3},
          {label: '通过', value: 1},
          {label: '拒绝', value: 2},
        ],
        tableData: [],
        page: 1,
        totalPage: 0,
        tableLoadingShow: false,
        admin_info:"",
        expertDetailVisible: false,//查看个性签名弹窗状态
        expertDetail:[],
      }
    },
    mounted(){
      this.getExpertAppointList();
      this.getAdminUserInfo();
    },
    watch:{
      'testFlag':function (val) {
        this.getExpertAppointList();
      }
    },
    methods:{
      //获取管理员信息
      async getAdminUserInfo(){
        let params = {
          user_token: window.localStorage.getItem('user_token'),
        }
        const res = await this.$api.getAdminUserInfo(params);
        console.log("res",res)
        if(res.data.level=='success'){
          this.noticeMessageCount = res.data.admin_message;
          this.admin_info = res.data.data;
        }else{

        }
      },
      async getExpertAppointList(){
        let params = {
          page: this.page,
          limit: 10,
          status: this.searchOption,
          keyword: this.searchText
        }
        const res = await this.$api.getExpertAppointList(params);
        if (res.data.level == 'success'){
          this.tableData = res.data.data;
          this.totalPage = res.data.page_info.total;
        }
        this.tableLoadingShow = false;
      },
      async confirmAppoint(id,status){
        let params = {
          id: id,
          status: status
        }
        const res = await this.$api.confirmAppoint(params);
        if (res.data.level == 'success'){
          this.$message.success(res.data.message);
          this.getExpertAppointList();
        } else {
          this.$message.error(res.data.message);
        }
      },
      pageChange(e) {
        //翻页
        this.page = e;
        this.getExpertAppointList();
      },
      search(){
        this.tableLoadingShow = true;
        this.page = 1;
        this.getExpertAppointList();
      },
      async showExpertDetail(id) {
        //显示专家详情
        let res = await this.$api.getExpertDetail({id: id});
        if (res.data.level == 'success') {
          this.expertDetail = res.data.data;
          this.expertDetailVisible = true
        } else {
          this.$message.error(res.data.message)
        }

      },
      initData() {

      },
    }
  }
</script>

<style lang="scss" scoped>
  .screen {
    margin-top: -10px !important;
  }

  .action-bar-wrapper {
    position: sticky;
    z-index: 1;
    top: -10px;
  }

  .action-bar {
    background-color: #f2f2f2;

    height: 60px;
    margin: 10px 0px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    padding-left: 20px;

    .action-bar-input {
      width: 250px;
      margin-right: 14px;
    }

    .task-form-text {
      color: #666666;
    }
  }

  .el-table-style {
    width: 100%;
    border: 1px solid #f2f2f2;
  }

  .footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f2f2f2;
    padding: 8px;
    margin: 10px 0px;
    box-sizing: border-box;
  }

  .dialog-footer {
    text-align: center;
  }

  .executorList {
    display: flex;
    flex-wrap: wrap;

    div {
      margin: 10px;
      border: 1px solid #eee;
      border-radius: 5px;
      padding: 5px 10px;
    }
  }


  .tag-wrapper {
    span {
      padding: 20px
    }
  }
</style>
